/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author gabrielbmoro
 */
public class Universidade extends DML {

    private String nome;
    private ConectaBD conecta;

    public Universidade(String nome) {
        this.nome = nome;
    }

    public Universidade() {
    }

    public ArrayList<Professor> recuperaProfessores() {
        String sql = "select nome from professor;";
        ArrayList<Professor> professores = new ArrayList<Professor>();

        try {
            this.conecta = ConectaBD.getInstance();
            super.statement = this.conecta.getConnection().createStatement();
            super.resultSet = super.statement.executeQuery(sql);
            while (super.resultSet.next()) {
                professores.add(new Professor(super.resultSet.getString(1)));
            }
            super.resultSet.close();
            super.statement.close();
            return professores;
        } catch (SQLException sqlErro) {
            sqlErro.printStackTrace();
        }
        return null;
    }

    public ArrayList<Professor> recuperaProfessores(String nomeProfessor) {
        String sql = "select nome from professor where nome!=\"" + nomeProfessor + "\";";
        ArrayList<Professor> professores = new ArrayList<Professor>();

        try {
            this.conecta = ConectaBD.getInstance();
            super.statement = this.conecta.getConnection().createStatement();
            super.resultSet = super.statement.executeQuery(sql);
            while (super.resultSet.next()) {
                String nome = super.resultSet.getString(1);
                Professor professor = new Professor(nome);
                professores.add(professor);
            }
            super.resultSet.close();
            super.statement.close();
            return professores;
        } catch (SQLException sqlErro) {
            sqlErro.printStackTrace();
        }
        return null;
    }

    /**
     * @return the nome
     */
    public String getNome() {
        return nome;
    }

    /**
     * @param nome the nome to set
     */
    public void setNome(String nome) {
        this.nome = nome;
    }
}
